package com.simonking.boot.mcp.client.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
import io.modelcontextprotocol.spec.McpClientTransport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.mcp.client.autoconfigure.NamedClientMcpTransport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Collections;
import java.util.List;

/**
 * 2、Spring AI SSE 方式接入 MCP 服务
 *
 * https://lbs.amap.com/api/mcp-server/gettingstarted#t1
 * #注意不要在配置文件中填写高德sse 连接
 *
 * {
 *   "mcpServers": {
 *     "amap-amap-sse": {
 *       "url": "https://mcp.amap.com/sse?key=ad74caf872b6246676f62d1b133fb38b"
 *     }
 *   }
 * }
 *
 *
 *
 * "filesystem": {
 * "command": "npx",
 * "args": [
 * "-y",
 * "@modelcontextprotocol/server-filesystem",
 *
 *
 *
 * "C:\\Users\\username\\Desktop",
 * "D:\\Projects\\MyDocs"
 * ]
 * }
 *
 */
@Slf4j
@Configuration
public class McpConfig {




    @Bean
    public List<NamedClientMcpTransport> mcpClientTransport() {
        McpClientTransport transport = HttpClientSseClientTransport
                .builder("https://mcp.amap.com")
                .sseEndpoint("/sse?key=ad74caf872b6246676f62d1b133fb38b")
                .objectMapper(new ObjectMapper())
                .build();

        return Collections.singletonList(new NamedClientMcpTransport("amap", transport));
    }

//    @Bean
//    public List<NamedClientMcpTransport> mcpClientTransport() {
//        McpClientTransport transport = HttpClientSseClientTransport
//                .builder("https://mcp.amap.com")
//                .sseEndpoint("/sse?key=ad74caf872b6246676f62d1b133fb38b")
//                .objectMapper(new ObjectMapper())
//                .build();
//
//        McpClientTransport transport2 = HttpClientSseClientTransport
//                .builder("http://172.16.33.186:5235")
//                .sseEndpoint("/mcp/user/sse?stream=true")
//                .objectMapper(new ObjectMapper())
//                .build();
//
//        List<NamedClientMcpTransport> amap = new java.util.ArrayList<>(Collections.singletonList(new NamedClientMcpTransport("amap", transport)));
//
//        amap.add(new NamedClientMcpTransport("BBBB", transport2));
//        return amap;
//    }

}